Skip to content

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Jul 13, 2020

Description
Fix regressions introduced by

This PR delays the imports and brings az version to its normal speed.

Testing Guide

# Before
> Measure-Command {az version}

TotalMilliseconds : 1132.3246

# After
> Measure-Command {az version}

TotalMilliseconds : 627.5202

@yonzhan
Copy link
Collaborator

yonzhan commented Jul 13, 2020

add to S173

@yonzhan yonzhan requested a review from jsntcy July 13, 2020 02:59
try:
# Import in the `for` loop because `allowed_extensions` can be []. In such case we
# don't need to import `check_version_compatibility` at all.
from azure.cli.core.extension.operations import check_version_compatibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing a module in a for loop is not a good practice.
How much can it benefit from importing in this for loop?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can import module as many times as you want in one Python program, no matter what module it is. Every subsequent import after the first accesses the cached module instead of re-evaluating it. So there is no performance penalty.


In reply to: 454774982 [](ancestors = 454774982)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky part. I just want to eliminate an extra if allowed_extensions:. Python has an import cache which will handle "import in a for loop" nicely.

Copy link
Member

@jsntcy jsntcy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Member

@qianwens qianwens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

is_windows, is_wsl
from azure.cli.core.cloud import get_active_cloud, set_cloud_subscription

from .adal_authentication import MSIAuthenticationWrapper
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsntcy, relative import it is not recommended according to PEP 8:

Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better error messages)...

@jiasli jiasli merged commit 776fe15 into Azure:dev Jul 15, 2020
@jiasli jiasli deleted the delay branch July 15, 2020 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants